package com.tjp.eight.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.tjp.eight.R;
import com.tjp.eight.base.BasePresenterImpl;

/**
 * Created by Administrator on 2017/3/31.
 */
public class FragmentWeb extends BaseFragment {
    WebView webView;
    String url = "";

    @Override
    protected BasePresenterImpl createPresenter() {
        return null;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        contentView = super.onCreateView(inflater, container, savedInstanceState);
        if (contentView == null) {
            contentView = inflater.inflate(R.layout.fragment_web, container, false);
        }
        initViews();
        return contentView;
    }

    void initViews() {
        url = getActivity().getIntent().getStringExtra("url");
        webView = (WebView) contentView.findViewById(R.id.wv_all_web_view);
        setWebView(webView);
        webView.setWebViewClient(new WebViewClient());
        webView.setWebChromeClient(new WebChromeClient());
        webView.loadUrl(url);
    }

    void setWebView(WebView view) {
        view.getSettings().setSupportZoom(false);
        view.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        view.getSettings().setJavaScriptEnabled(true);
        view.getSettings().setDefaultTextEncodingName("UTF-8");
        view.getSettings().setAppCacheEnabled(false);
        view.getSettings().setSaveFormData(true);// 保存表单数据
        view.getSettings().setJavaScriptEnabled(true);
        view.getSettings().setGeolocationEnabled(true);// 启用地理定位
        view.getSettings().setDomStorageEnabled(true);
        view.getSettings().setSupportMultipleWindows(true);// 新加
    }

}
